package com.dqlp.yf.rabbitmq.receive;

import com.dqlp.yf.rabbitmq.constant.MqConstant;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @program: rabbitmq
 * @description:
 * @author: andy
 * @create: 2019-09-08 23:17
 */
@Component
@Slf4j
public class TopicCustomer {
    @RabbitListener(
            bindings = @QueueBinding(
                    exchange = @Exchange(value = MqConstant.TOPIC_EXCHANGE, type = ExchangeTypes.TOPIC,
                            durable = "true", autoDelete = "false"),
                    value = @Queue(value = MqConstant.TOPIC_QUEUE, durable = "true"),
                    key = MqConstant.TPOIC_ROUTERKEY))
    public void topicCustomer(Message message, Channel channel) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.out.println(deliveryTag+"*************");
        channel.basicAck(deliveryTag,false);
    }

}
